import maya.cmds as mc

class general_command():
    def  __init__(self):
        pass
    
    
    def makeObjReferenced(self , obj = '' ):
        
        Shapes = mc.listRelatives( obj ,s=True  )
        for sp in Shapes:
            mc.setAttr( str(sp)+'.overrideEnabled' , 1 )
            mc.setAttr( str(sp)+'.overrideDisplayType' , 2 )
    
    def LZ_creatJoint(self,parentConsobj,jntname):
        mc.select(cl=True)
        mc.joint(n=jntname)
        mc.parentConstraint(parentConsobj,jntname,mo=False,n='templeconstraint')
        mc.delete('templeconstraint')
        secjntRX=mc.getAttr(str(jntname)+'.rx')
        secjntRY=mc.getAttr(str(jntname)+'.ry')
        secjntRZ=mc.getAttr(str(jntname)+'.rz')
        
        mc.setAttr(str(jntname)+'.jointOrient',secjntRX,secjntRY,secjntRZ)
        mc.setAttr(str(jntname)+'.rotate',0,0,0)
        
    def makeZeroGrpTwo(self,OrgObj = [''],sufname='_zero',cenObj='',Mode=0,type = 'group',ro =True):    #  type = 'group'   or type  ='joint'
    #   mode == 1:  replace;  mode == 0:  add  
        seleobj=mc.ls(sl=True)
        group_all =[]

        for i in OrgObj:
            if cenObj=='':
                cenParent=i
            else:
                cenParent=cenObj
            if Mode==0:
                groupname=str(i)+sufname
            if Mode==1:
                regName=str(i).split('_')
                groupname=str(i).replace(regName[-1],sufname)
                
            if type == 'group':
                mc.group(n=groupname,em=True)
            elif type == 'joint':
                mc.select(cl=True)
                mc.joint( n =groupname )
            parent=mc.listRelatives(i,p=True)
            mc.pointConstraint(cenParent,groupname,mo=False,n='needDeleteConstriant',w=1)
            mc.delete('needDeleteConstriant')
            if ro == True:
                mc.orientConstraint(cenParent,groupname,mo=False,n='needDeleteConstriant',w=1)
                
                mc.delete('needDeleteConstriant')
                
                if type =='joint':
                    self.frozeen_jnt_Transform( groupname )
            mc.parent(i,groupname)
            if parent==None:
                pass
            else:
                mc.parent(groupname,parent)
                
            group_all.append(groupname)
        mc.select(OrgObj)
        return(group_all)
        
    def LZ_createCurve_ep(self,curveName = '' , position = [(0,0,0)]):
        curveName = mc.curve(n=curveName ,ep = position)
        
        return curveName
        
    def find_max2Min_list(self,locTemp = ['','','']):
        
        temp_info = []
        for lt in locTemp:
            lt_pos = mc.xform( lt ,q=True,t=True,ws=True )
            temp_info.append((lt,(lt_pos[0],lt_pos[1],lt_pos[2])))
        
        number_tem = len( temp_info )
        state_number_tem = len( temp_info )
        
        
        #maxObj = temp_info[0][0]
        
        
        maxSequenceList = []
        
        for i in range( state_number_tem  ):
            maxValue = temp_info[0][1][0] 

            max_info = temp_info[0]
            for num in range(number_tem):

                if  number_tem-1 != 0:
                    if temp_info[num][1][0] > maxValue:
                        maxValue = temp_info[num][1][0]
                        #maxObj = temp_info[num][0]
                        max_info = temp_info[num]
                        
                        #print(max_info,'====',temp_info)
                    else:
                        pass
                else:
                    max_info = temp_info[0]
                

            temp_info.remove( max_info )
            
            maxSequenceList.append(max_info)

            number_tem = number_tem -1
            
        return maxSequenceList
 
        
    def createTransformer(self,locName = '',position = ( 0,0,0),rotation = ( 0,0,0) ,type = 'locator',LocPosion = (0,0,0)):
        if type =='locator': 
            mc.spaceLocator(  n = locName ,p = LocPosion )
        elif type =='group':
            mc.group( em = True , n= locName)
            
        elif type =='joint':
            mc.select(cl=True)
            mc.joint(n= locName) 
        
        mc.move( position[0], position[1],position[2], locName )
        mc.rotate( rotation[0], rotation[1],rotation[2], locName )
        
        if type =='joint':
            secjntRX=mc.getAttr(str(locName)+'.rx')
            secjntRY=mc.getAttr(str(locName)+'.ry')
            secjntRZ=mc.getAttr(str(locName)+'.rz')
            
            mc.setAttr(str(locName)+'.jointOrient',secjntRX,secjntRY,secjntRZ)
            mc.setAttr(str(locName)+'.rotate',0,0,0)
        
    def LZ_connectAttr(self,outputObj = '',inputObj = '',attribute = '.translate',inverseX = 1,inverseY = 1,inverseZ = 1):
        
        attr = str(attribute).split('.')[-1]
        node = str(inputObj)+'_'+attr+'_con_md'
        node_md = mc.createNode('multiplyDivide',n = node)
        
        mc.connectAttr( str(outputObj)+attribute , str(node_md)+'.input1')
        mc.connectAttr(  str(node_md)+'.output' ,str(inputObj)+attribute)
        
        mc.setAttr(str(node_md)+'.input2X',inverseX)
        mc.setAttr(str(node_md)+'.input2Y',inverseY)
        mc.setAttr(str(node_md)+'.input2Z',inverseZ)
        
    def LZ_connectAttr_02(self,outputObj = '',inputObj = '',outputattribute = ['.translateX','.translateY','.translateZ'],inputattribute = ['.translateX','.translateY','.translateZ'],inverseX = 1,inverseY = 1,inverseZ = 1):
        
        attr = str(inputattribute[0]).split('.')[-1]
        node = str(inputObj)+'_'+attr+'_con_md'
        
        
        if mc.objExists(node) == 0:
            node_md = mc.createNode('multiplyDivide',n = node)
            
            if outputattribute[0]!='':
                mc.connectAttr( str(outputObj)+outputattribute[0] , str(node_md)+'.input1X')
            if outputattribute[1]!='':
                mc.connectAttr( str(outputObj)+outputattribute[1] , str(node_md)+'.input1Y')
            if outputattribute[2]!='':
                mc.connectAttr( str(outputObj)+outputattribute[2] , str(node_md)+'.input1Z')
            
            if inputattribute[0]!='':
                if mc.listConnections ( str(inputObj)+inputattribute[0],s=True , d=False ) == None:
                    mc.connectAttr(  str(node_md)+'.outputX' ,str(inputObj)+inputattribute[0])
            
            if inputattribute[1]!='':
                if mc.listConnections ( str(inputObj)+inputattribute[1],s=True , d=False  ) == None:
                    mc.connectAttr(  str(node_md)+'.outputY' ,str(inputObj)+inputattribute[1])
            
            if inputattribute[2]!='':
                if mc.listConnections ( str(inputObj)+inputattribute[2],s=True , d=False  ) == None:
                    mc.connectAttr(  str(node_md)+'.outputZ' ,str(inputObj)+inputattribute[2])
            
            mc.setAttr(str(node_md)+'.input2X',inverseX)
            mc.setAttr(str(node_md)+'.input2Y',inverseY)
            mc.setAttr(str(node_md)+'.input2Z',inverseZ)
    
    
    def plane_8dir_sdk(self , driver = '' ,firstAttr = 'tx' ,secondryAttr = 'ty',dircNormalValue = [10,10,10,10] ):
        ## =====  create a multiplyDivid node to normalize the value()
        normal_md = driver+'_8dir_driver_md'
        
        normal01_condition = driver+'_8dir_driver01_condition'
        normal02_condition = driver+'_8dir_driver02_condition'
        
        mc.createNode('multiplyDivide' , n = normal_md )
        mc.setAttr(str(normal_md)+'.operation',2)
        
        mc.createNode( 'condition' , n = normal01_condition )
        mc.connectAttr( str(driver)+'.' + firstAttr , str(normal01_condition) + '.firstTerm')
        mc.setAttr( str(normal01_condition) + '.operation', 2 )
        mc.setAttr( str(normal01_condition) + '.colorIfTrueR', dircNormalValue[0] )
        mc.setAttr( str(normal01_condition) + '.colorIfFalseR', dircNormalValue[1] )
        
        
        mc.createNode( 'condition' , n = normal02_condition )
        mc.connectAttr( str(driver)+'.' + secondryAttr , str(normal02_condition) + '.firstTerm')
        mc.setAttr( str(normal02_condition) + '.operation', 2 )
        mc.setAttr( str(normal02_condition) + '.colorIfTrueR', dircNormalValue[2] )
        mc.setAttr( str(normal02_condition) + '.colorIfFalseR', dircNormalValue[3] )
        
        #########
        mc.connectAttr( str(driver)+'.'+firstAttr , str(normal_md)+'.input1X' )
        mc.connectAttr( str(driver)+'.'+secondryAttr , str(normal_md)+'.input1Y' )
        
        mc.connectAttr( str(normal01_condition)+'.outColorR' , str(normal_md)+'.input2X' )
        mc.connectAttr( str(normal02_condition)+'.outColorR' , str(normal_md)+'.input2Y' )
        
        ####======  create clamp node to limit the max and min value output
        positiveClamp = driver + '_8dir_driver_pos_clamp'
        negativeClamp = driver + '_8dir_driver_neg_clamp'
        
        mc.createNode( 'clamp' ,n = positiveClamp )
        mc.createNode( 'clamp' ,n = negativeClamp )
        
        mc.connectAttr( str(normal_md) + '.output',str(positiveClamp)+'.input' )
        mc.connectAttr( str(normal_md) + '.output',str(negativeClamp)+'.input' )
        
        mc.setAttr( str(positiveClamp)+'.maxR' ,1 )
        mc.setAttr( str(positiveClamp)+'.maxG' ,1 )
        mc.setAttr( str(positiveClamp)+'.maxB' ,1 )
        
        mc.setAttr( str(negativeClamp)+'.minR' ,-1 )
        mc.setAttr( str(negativeClamp)+'.minG' ,-1 )
        mc.setAttr( str(negativeClamp)+'.minB' ,-1 )
        
        #### =====================  create invese value node  
        
        pos_reverse = driver + '_8dir_driver_pos_reverse'
        neg_reverse = driver + '_8dir_driver_neg_reverse'
        
        neg_reverseNormalize_md =  driver + '_8dir_driver_neg_reverseNromalize_md'
        
        mc.createNode( 'multiplyDivide' , n= neg_reverseNormalize_md )
        mc.setAttr( str(neg_reverseNormalize_md)+'.input2X' ,-1)
        mc.setAttr( str(neg_reverseNormalize_md)+'.input2Y' ,-1)
        
        mc.connectAttr( str(negativeClamp)+'.outputR'  , str(neg_reverseNormalize_md)+'.input1X')
        mc.connectAttr( str(negativeClamp)+'.outputG'  , str(neg_reverseNormalize_md)+'.input1Y')
        
        mc.createNode( 'reverse' , n= pos_reverse )
        mc.createNode( 'reverse' , n= neg_reverse )
        
        mc.connectAttr( str(positiveClamp)+'.outputR'  ,str(pos_reverse)+ '.inputX')
        mc.connectAttr( str(positiveClamp)+'.outputG'  ,str(pos_reverse)+ '.inputY')
        
        mc.connectAttr( str(neg_reverseNormalize_md)+'.outputX'  ,str(neg_reverse)+ '.inputX')
        mc.connectAttr( str(neg_reverseNormalize_md)+'.outputY'  ,str(neg_reverse)+ '.inputY')
        
        ##  =====================  create base part mltiyDivide node 
        
        part_md_all = [driver + '_8dir_driver_up_out_md' ,
                       driver + '_8dir_driver_up_in_md' ,
                       driver + '_8dir_driver_out_up_md' ,
                       driver + '_8dir_driver_out_dn_md' ,
                       driver + '_8dir_driver_dn_out_md' ,
                       driver + '_8dir_driver_dn_in_md' ,
                       driver + '_8dir_driver_in_up_md' ,
                       driver + '_8dir_driver_in_dn_md' 
                        

                        ]
        mc.createNode( 'multiplyDivide' , n = part_md_all[0] )
        mc.connectAttr( str(positiveClamp)+'.outputG'  , str(part_md_all[0])+'.input1X' )
        mc.connectAttr( str(pos_reverse)+'.outputX'  , str(part_md_all[0])+'.input2X' )
        
        #mc.createNode( 'multiplyDivide' , n = part_md_all[1] )
        #mc.connectAttr( str(positiveClamp)+'.outputG'  , str(part_md_all[1])+'.input1X' )
        #mc.connectAttr( str(neg_reverse)+'.outputX'  , str(part_md_all[1])+'.input2X' )
        
        mc.createNode( 'multiplyDivide' , n = part_md_all[2] )
        mc.connectAttr( str(positiveClamp)+'.outputR'  , str(part_md_all[2])+'.input1X' )
        mc.connectAttr( str(pos_reverse)+'.outputY'  , str(part_md_all[2])+'.input2X' )
        
        #mc.createNode( 'multiplyDivide' , n = part_md_all[3] )
        #mc.connectAttr( str(positiveClamp)+'.outputR'  , str(part_md_all[3])+'.input1X' )
        #mc.connectAttr( str(neg_reverse)+'.outputY'  , str(part_md_all[3])+'.input2X' )
        
        
        mc.createNode( 'multiplyDivide' , n = part_md_all[4] )
        mc.connectAttr( str(neg_reverseNormalize_md)+'.outputY'  , str(part_md_all[4])+'.input1X' )
        mc.connectAttr( str(pos_reverse)+'.outputX'  , str(part_md_all[4])+'.input2X' )
        
        #mc.createNode( 'multiplyDivide' , n = part_md_all[5] )
        #mc.connectAttr( str(neg_reverseNormalize_md)+'.outputY'  , str(part_md_all[5])+'.input1X' )
        #mc.connectAttr( str(neg_reverse)+'.outputX'  , str(part_md_all[5])+'.input2X' )
        
        mc.createNode( 'multiplyDivide' , n = part_md_all[6] )
        mc.connectAttr( str(neg_reverseNormalize_md)+'.outputX'  , str(part_md_all[6])+'.input1X' )
        mc.connectAttr( str(pos_reverse)+'.outputY'  , str(part_md_all[6])+'.input2X' )
        
        #mc.createNode( 'multiplyDivide' , n = part_md_all[7] )
        #mc.connectAttr( str(neg_reverseNormalize_md)+'.outputX'  , str(part_md_all[7])+'.input1X' )
        #mc.connectAttr( str(neg_reverse)+'.outputY'  , str(part_md_all[7])+'.input2X' )
        
        
        ###==============================  create sdk driver multiplyDivide node
        bridge = driver + '_driver_bridge'
        mc.group(em=True,n=bridge)
        
        attrAdd = ['up_driver','out_driver','dn_driver','inn_driver','upOut_driver','upInn_driver','dnOut_driver','dnInn_driver']
        
        for ad in attrAdd:
            mc.addAttr( bridge ,ln = ad )
            mc.setAttr(str(bridge)+'.'+ad,k=True)
        
        
        output_md_all = [driver + '_8dir_driver_output_up_md' ,
                       driver + '_8dir_driver_output_out_md' ,
                       driver + '_8dir_driver_output_dn_md' ,
                       driver + '_8dir_driver_ouput_in_md' ,
                       driver + '_8dir_driver_output_upOut_md' ,
                       driver + '_8dir_driver_output_upInn_md' ,
                       driver + '_8dir_driver_output_dnOut_md' ,
                       driver + '_8dir_driver_output_dnInn_md' 
                        

                        ]
        
        mc.createNode('multiplyDivide',n= output_md_all[0] )
        mc.connectAttr( str(part_md_all[0])+'.outputX'  , str(output_md_all[0])+'.input1X' )
        mc.connectAttr( str(neg_reverse)+'.outputX'  , str(output_md_all[0])+'.input2X' )
        mc.connectAttr( str(output_md_all[0])+'.outputX'  , str(bridge)+'.'+attrAdd[0] )
        
        
        mc.createNode('multiplyDivide',n= output_md_all[1] )
        mc.connectAttr( str(part_md_all[2])+'.outputX'  , str(output_md_all[1])+'.input1X' )
        mc.connectAttr( str(neg_reverse)+'.outputY'  , str(output_md_all[1])+'.input2X' )
        mc.connectAttr( str(output_md_all[1])+'.outputX'  , str(bridge)+'.'+attrAdd[1] )
        
        mc.createNode('multiplyDivide',n= output_md_all[2] )
        mc.connectAttr( str(part_md_all[4])+'.outputX'  , str(output_md_all[2])+'.input1X' )
        mc.connectAttr( str(neg_reverse)+'.outputX'  , str(output_md_all[2])+'.input2X' )
        mc.connectAttr( str(output_md_all[2])+'.outputX'  , str(bridge)+'.'+attrAdd[2] )
        
        mc.createNode('multiplyDivide',n= output_md_all[3] )
        mc.connectAttr( str(part_md_all[6])+'.outputX'  , str(output_md_all[3])+'.input1X' )
        mc.connectAttr( str(neg_reverse)+'.outputY'  , str(output_md_all[3])+'.input2X' )
        mc.connectAttr( str(output_md_all[3])+'.outputX'  , str(bridge)+'.'+attrAdd[3] )
        
        mc.createNode('multiplyDivide',n= output_md_all[4] )
        mc.connectAttr( str(positiveClamp)+'.outputR'  , str(output_md_all[4])+'.input1X' )
        mc.connectAttr( str(positiveClamp)+'.outputG'  , str(output_md_all[4])+'.input2X' )
        mc.connectAttr( str(output_md_all[4])+'.outputX'  , str(bridge)+'.'+attrAdd[4] )
        
        mc.createNode('multiplyDivide',n= output_md_all[5] )
        mc.connectAttr( str(positiveClamp)+'.outputG'  , str(output_md_all[5])+'.input1X' )
        mc.connectAttr( str(neg_reverseNormalize_md)+'.outputX'  , str(output_md_all[5])+'.input2X' )
        mc.connectAttr( str(output_md_all[5])+'.outputX'  , str(bridge)+'.'+attrAdd[5] )
        
        mc.createNode('multiplyDivide',n= output_md_all[6] )
        mc.connectAttr( str(neg_reverseNormalize_md)+'.outputY'  , str(output_md_all[6])+'.input1X' )
        mc.connectAttr( str(positiveClamp)+'.outputR'  , str(output_md_all[6])+'.input2X' )
        mc.connectAttr( str(output_md_all[6])+'.outputX'  , str(bridge)+'.'+attrAdd[6] )
        
        mc.createNode('multiplyDivide',n= output_md_all[7] )
        mc.connectAttr( str(neg_reverseNormalize_md)+'.outputX'  , str(output_md_all[7])+'.input1X' )
        mc.connectAttr( str(neg_reverseNormalize_md)+'.outputY'  , str(output_md_all[7])+'.input2X' )
        mc.connectAttr( str(output_md_all[7])+'.outputX'  , str(bridge)+'.'+attrAdd[7] )
        
        
        return bridge
        
    def create_secondry_grp(self,ctrl_name = '',position =(0,0,0),IfInverse = 0):
        self.createTransformer(locName = ctrl_name ,position = position ,rotation = ( 0,0,0) ,type = 'group',LocPosion = (0,0,0))
        zerogrp = self.makeZeroGrpTwo( OrgObj = [ ctrl_name ],sufname='_zero',cenObj = '' ,Mode=0,type = 'group',ro =True)
        self.makeZeroGrpTwo( OrgObj = [ ctrl_name ],sufname='rivet',cenObj = '' ,Mode=1,type = 'group',ro =True)[0]
        offseGrp = self.makeZeroGrpTwo( OrgObj = [ ctrl_name ],sufname='offset',cenObj = '' ,Mode=1,type = 'group',ro =True)[0]
        poivt = self.makeZeroGrpTwo( OrgObj = [ ctrl_name ],sufname='pivot',cenObj = '' ,Mode=1,type = 'group',ro =True)[0]
        
        self.LZ_connectAttr( outputObj = ctrl_name ,inputObj = poivt ,attribute = '.translate',inverseX = -1,inverseY = -1,inverseZ = -1)
        if IfInverse == 1:
            mc.setAttr(str(offseGrp)+'.scaleX',-1)
            
        return zerogrp    
    
    def create_secondry_grpForNose(self,ctrl_name = '',position =(0,0,0),rotete=(0,0,0),rivetposition = '' , IfInverse = 0):
        self.createTransformer(locName = ctrl_name ,position = position ,rotation = rotete ,type = 'group',LocPosion = (0,0,0))
        zerogrp = self.makeZeroGrpTwo( OrgObj = [ ctrl_name ],sufname='_zero',cenObj = '' ,Mode=0,type = 'group',ro =True)[0]
        
        offseGrp = self.makeZeroGrpTwo( OrgObj = [ ctrl_name ],sufname='offset',cenObj = '' ,Mode=1,type = 'group',ro =True)[0]
        poivt = self.makeZeroGrpTwo( OrgObj = [ ctrl_name ],sufname='pivot',cenObj = '' ,Mode=1,type = 'group',ro =True)[0]
        
        self.LZ_connectAttr( outputObj = ctrl_name ,inputObj = poivt ,attribute = '.translate',inverseX = -1,inverseY = -1,inverseZ = -1)
        if IfInverse == 1:
            mc.setAttr(str(offseGrp)+'.scaleX',-1)
        

        rivetGrp = self.makeZeroGrpTwo( OrgObj = [ zerogrp ],sufname='rivet',cenObj = rivetposition ,Mode=1,type = 'group',ro =True)[0]
        rivetZero = self.makeZeroGrpTwo( OrgObj = [ rivetGrp ],sufname='_zero',cenObj = '' ,Mode=0,type = 'group',ro =True)[0]
        return rivetZero   
        
        
    ####################################################################################################
    #------------------------------- create inverseMatrix   ------------------------------------------
    def createRecerseJnt(self,stept):
        
        seleJnt=mc.ls(sl=True)
        
        for k in seleJnt:
            mc.select(k)
            for i in range(stept):
                mc.pickWalk(d='up')
            
            parentname=mc.ls(sl=True)[0]
            splitname=str(k).split('_')    
            reversename=str(k).replace(splitname[-1],'reverse')
            
            mc.duplicate(k,n=reversename)
            mc.setAttr(str(reversename)+'.visibility',0)
            if stept>1:
                mc.parent(reversename,parentname)
    def conneReverseAttr(self,skinname,IsAllCluters):
        
        jntConnectAll=[]
        worldMatrixAttr=[]
        
        # skinname='skinCluster6'
        connectAttrs=mc.listConnections(skinname,s=True,p=True,c=True,scn=True)
        for m in connectAttrs:
            if 'worldMatrix' in m:
                worldMatrixAttr.append(m)
        for i in worldMatrixAttr:
            ojbConnect=str(i).split('.')[0]
            jntConnectAll.append(ojbConnect)
            
            if IsAllCluters == 1:
    
                connectedMatrixAttr=mc.listConnections(i,d=True,p=True)
    
          
                for k in connectedMatrixAttr:
                
            
                    bindAttr=str(k).replace('matrix','bindPreMatrix')
                    splitname=str(ojbConnect).split('_')
                    reversename=str(ojbConnect).replace(splitname[-1],'reverse')
            
                    attrIsConnect=mc.listConnections(bindAttr,s=True)
                    if attrIsConnect==None: 
                        mc.connectAttr(str(reversename)+'.worldInverseMatrix[0]',bindAttr)

            if IsAllCluters == 0:
                connectedMatrixAttrs=mc.listConnections(i,d=True,p=True)
                
                for cmas in connectedMatrixAttrs:
                    if skinname in cmas:
                        connectedMatrixAttr=cmas
    
                orgbindAttr=str(connectedMatrixAttr).replace('matrix','bindPreMatrix')
                replacename=str(connectedMatrixAttr).split('.')[0]
                bindAttr=str(orgbindAttr).replace(replacename,skinname)
                
                splitname=str(ojbConnect).split('_')
                reversename=str(ojbConnect).replace(splitname[-1],'reverse')
    
                attrIsConnect=mc.listConnections(bindAttr,s=True)
                if attrIsConnect==None: 
                    mc.connectAttr(str(reversename)+'.worldInverseMatrix[0]',bindAttr)

        sys.stdout.write('" ok,,inverseMatrix has connected the skinCluster!! "')
        
    def conneReverseAttr_singgle(self,inputJnt = '' ,revertJnt = '', skinname = ''  ):
        influnece_objs = mc.skinCluster( skinname  , q = True , influence = True )
        worldMatrixAttr=[]
        
        if inputJnt in influnece_objs:
            connectAttrs=mc.listConnections(skinname,s=True,p=True,c=True,scn=True)
            
            for m in connectAttrs:
                if 'worldMatrix' in m:
                    worldMatrixAttr.append(m)
            
            for i in worldMatrixAttr:
                ojbConnect=str(i).split('.')[0]
                #jntConnectAll.append(ojbConnect)
                
                if ojbConnect == inputJnt:
                
                    connectedMatrixAttrs=mc.listConnections(i,d=True,p=True)
                    
                    for cmas in connectedMatrixAttrs:
                        if skinname in cmas:
                            connectedMatrixAttr=cmas
                    
                    orgbindAttr=str(connectedMatrixAttr).replace('matrix','bindPreMatrix')
                    replacename=str(connectedMatrixAttr).split('.')[0]
                    bindAttr=str(orgbindAttr).replace(replacename,skinname)
                    
                    #splitname=str(ojbConnect).split('_')
                    #reversename=str(ojbConnect).replace(splitname[-1],'reverse')
                    
                    
                    
                    
                    attrIsConnect=mc.listConnections(bindAttr,s=True)
                    if attrIsConnect==None: 
                        mc.connectAttr(str(revertJnt)+'.worldInverseMatrix[0]',bindAttr)
                    
    
    
    ##=============================================================================================
    #--------------------- skincluster  transform deformer weight ------------------------------------------------------------
    
            